/**
 * Copyright 2008 Matthew Purland (m.purland@gmail.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.variance.version;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

import org.variance.version.identifier.RevisionIdentifier;
import org.variance.version.identifier.RevisionIdentifierSource;

/**
 *
 *
 * @todo Auto-generated doc stub for MockRevisionIdentifierSource.
 *
 * @author Matthew Purland
 */
public class MockRevisionIdentifierSource implements RevisionIdentifierSource {

    private List<RevisionIdentifier> existingRevisionIdentifier = new ArrayList<RevisionIdentifier>();
    private List<RevisionIdentifier> availableRevisionIdentifiers = new ArrayList<RevisionIdentifier>();


    /**
     * {@inheritDoc}
     */
    public void addIdentifier(RevisionIdentifier identifier) {
        availableRevisionIdentifiers.add(identifier);
    }

    /**
     * {@inheritDoc}
     */
    public void removeIdentifier(RevisionIdentifier identifier) {
        availableRevisionIdentifiers.remove(identifier);

    }

    /**
     * {@inheritDoc}
     */
    public RevisionIdentifier getAvailableIdentifier() throws NoSuchElementException {
        // Return null if there no available identifiers
        if (!hasAvailableIdentifiers()) {
            throw new NoSuchElementException("No available identifiers to get.");
        }

        RevisionIdentifier availableIdentifier = availableRevisionIdentifiers.remove(0);
        existingRevisionIdentifier.add(availableIdentifier);
        return availableIdentifier;
    }

    /**
     * {@inheritDoc}
     */
    public boolean hasAvailableIdentifiers() {
        // It has available identifiers if it is not empty
        return availableRevisionIdentifiers.size() > 0;
    }

    /**
     * {@inheritDoc}
     */
    public boolean isLatest(RevisionIdentifier revisionIdentifier) {
        if (revisionIdentifier.compareTo(existingRevisionIdentifier.get(0)) >= 0) {
            return true;
        }
        else {
            return false;
        }
    }



}
